<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" inline=true v-show="showSearch" label-width="68px">
      <el-form-item label="工单编号" prop="order_no">
        <el-input
          v-model="queryParams.order_no"
          placeholder="编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工单状态" prop="ro_status">
        <el-select v-model="queryParams.ro_status" placeholder="工单状态" clearable>
          <el-option
           v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="选择时间" prop="create_time">
       <el-time-picker
    v-model="value1" :picker-options="{selectableRange: '00:00:00 - 23:59:59'}"
    placeholder="选择时间">
  </el-time-picker>
  </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">

      <el-col :span="10" >
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['monitor:job:export']"
        >导出</el-button>
      </el-col>

       <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="myOrderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="工单编号" width="100" align="center" prop="orderNo" />
      <el-table-column label="问题内容" align="center" prop="describe" :show-overflow-tooltip="true" />
       <el-table-column label="工单发起人" align="center" prop="deptSumbitP">
      </el-table-column>
      <el-table-column label="工单问题类型" align="center" prop="deptSumbit">
      </el-table-column>
      <el-table-column label="提交时间" align="center" prop="createTime" :show-overflow-tooltip="true" />


      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">{{ getLabel (getStatus,scope.row.status,'dictValue','dictLabel')}}</template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">



   <template slot-scope="scope">

        <router-link :to="{path:'/transferdatails/'+orderNo1}">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['monitor:job:edit']"
          >查看并转接</el-button>
           </router-link>
           <!-- <router-view></router-view> -->

          <!-- <el-dropdown size="mini" @command="(command) => handleCommand(command, scope.row)" v-hasPermi="['work:myorder:edit']"> -->
            <!-- <span class="el-dropdown-link">
              <i class="el-icon-d-arrow-right el-icon--right"></i>更多
            </span> -->
            <!-- <el-dropdown-menu slot="dropdown"> -->
              <!-- <el-dropdown-item command="handleDataScope" icon="el-icon-circle-check"
                v-hasPermi="['system:role:edit']">数据权限</el-dropdown-item> -->
              <!-- <el-dropdown-item command="handleIndex" icon="el-icon-user"
                v-hasPermi="['work:myorder:edit']">转接</el-dropdown-item> -->
            <!-- </el-dropdown-menu> -->
          <!-- </el-dropdown> -->
          
        <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:post:edit']"
          >转接</el-button> -->
         <!-- <el-button type="text" @click="dialogFormVisible = true">转接</el-button> -->

        </template>
        
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

     <!-- 添加或修改岗位对话框 -->
    <!-- <el-dialog title="收货地址" :visible.sync="dialogFormVisible">
  <el-form :model="form">
    <el-form-item label="活动名称" :label-width="formLabelWidth">
      <el-input v-model="form.name" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="活动区域" :label-width="formLabelWidth">
      <el-select v-model="form.region" placeholder="请选择活动区域">
        <el-option label="区域一" value="shanghai"></el-option>
        <el-option label="区域二" value="beijing"></el-option>
      </el-select>
    </el-form-item>
  </el-form>
  <div slot="footer" class="dialog-footer">
    <el-button @click="dialogFormVisible = false">取 消</el-button>
    <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>
  </div>
</el-dialog> -->

  </div>
</template>

<script>
// import { listJob, getJob, delJob, addJob, updateJob, runJob, changeJobStatus } from "@/api/monitor/job";
// import Crontab from '@/components/Crontab'
import {selectMyTransfer}from "@/api/repair/transfer"

export default {
  // components: { Crontab },
  name: "Transfer",
  data() {
    return {
      //时间选择器
      value1: new Date(2016, 9, 10, 18, 40),
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 定时任务表格数据
      myOrderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示详细弹出层
      openView: false,
      //路由传值工单编号
      orderNo1:"",

      getStatus:[
        {dictValue:1,dictLabel:'申请转接'},
        {dictValue:2,dictLabel:'已转接'},
        {dictValue:3,dictLabel:'拒绝转接'}
      ],
      // dialogFormVisible: false,
      //   form: {
      //     name: '',
      //     region: '',
      //     date1: '',
      //     date2: '',
      //     delivery: false,
      //     type: [],
      //     resource: '',
      //     desc: ''
      //   },
      //   formLabelWidth: '100px',

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 5,
        order_no: undefined,
        ro_status: this.value,
        create_time: this.value1,
      },
      //工单状态
       options: [{
          value: '1',
          label: '工单受理中'
        }, {
          value: '2',
          label: '工单已派单'
        }, {
          value: '3',
          label: '待您反馈'
        }, {
          value: '4',
          label: '正在为您处理'
        }, {
          value: '5',
          label: '工单已关闭'
        }],
        value: ''
      ,
      // 表单参数
      // form: {},
      // 表单校验
      rules: {
        order_no: [
          { required: true, message: "工单编号不能为空", trigger: "blur" }
        ],
        ro_status: [
          { required: true, message: "工单状态不能为空", trigger: "blur" }
        ],
        create_time: [
          { required: true, message: "提交时间不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
    
  },
  methods: {
    getLabel(list,id,value,label){
  if(id !='' && Array.isArray(list)&& list.length !=0){
    return !list.find(item => item[value] == id)? id : list.find(item => item[value] == id)[label]
  }else{
      return id
    }
  },

    
     /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.postId != undefined) {
            updateTransfer(this.form).then(response => {
              this.$modal.msgSuccess("转接成功");
              this.open = false;
              this.getList();
            });
          } 
          // else {
          //   addPost(this.form).then(response => {
          //     this.$modal.msgSuccess("新增成功");
          //     this.open = false;
          //     this.getList();
          //   });
          // }
        }
      });
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // // 更多操作触发
    // handleCommand(command, row) {
    //   switch (command) {
    //     case "handleDataScope":
    //       this.handleDataScope(row);
    //       break;
    //     case "handleIndex":
    //       this.handleIndex(row);
    //       break;
    //     default:
    //       break;
    //   }
    // },
    // /** 分配用户操作 */
    // handleIndex: function(row) {
    //   const roleId = row.roleId;
    //   this.$router.push("/work/datails/index" + roleId);
    // },

    /** 查询我的工单列表 */
    getList() {
      this.loading = true;
      selectMyTransfer(this.queryParams).then(res => {
        console.log(res);
        this.$modal.msgSuccess("查询成功");
        this.myOrderList = res.data;
        

        this.total = res.total;
        this.loading = false;
      });
    },


    // 表单重置
    reset() {
      this.form = {
        order_no: undefined,

        ro_status: undefined,
        create_time: undefined,


      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.order_no);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },

    /** 转接按钮操作 */
    handleUpdate(row) {    
      this.orderNo1=row.orderNo
      this.reset();
      
    },

    /** 删除按钮操作 */
    // handleDelete(row) {
    //   const order_noIds = row.orderNo || this.ids;
    //   this.$modal.confirm('是否确认删除定时任务编号为"' + order_noIds + '"的数据项？').then(function() {
    //     return delTransfer(order_noIds);
    //   }).then(() => {
    //     this.getList();
    //     this.$modal.msgSuccess("删除成功");
    //   }).catch(() => {});
    // },
    /** 导出按钮操作 */
    handleExport() {
      this.download('monitor/job/export', {
        ...this.queryParams
      }, `order_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
